<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">系统管理</a>
        <a><cite>升级管理</cite></a>
        <a><cite>升级列表</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
                                <button class="layui-btn ts-app-table-operate" lay-href="/app/add"><i class="layui-icon">
                                    &#xe654;</i>添加升级
                                </button>
                            </div>
                        </div>
                    </div>
                    <!-- </form>-->
                    <table class="layui-hide" id="ts-app-table" lay-filter="ts-app-table">
                    </table>
                    <script type="text/html" id="ts-app-table-operate-bar">
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['admin', 'table','common'], function () {
        var table = layui.table;
        var admin = layui.admin,common =  layui.common;
        //初始化列表数据
        table.render({
            elem: '#ts-app-table'
            , url: '/system/tsApp/findTsAppPage.do'
            , where: {
                access_token: layui.data('layuiAdmin').access_token
            }
            , height: 'full-280'
            , cellMinWidth: 80
            , page: true
            , limit: 10
            , cols: [[
                {field: 'id', checkbox: true, fixed: true}
                , {field: 'version', title: '版本号', width: 200, sort: true, fixed: 'left'}
                , {field: 'content', title: '更新内容', width: 150, sort: true}
                , {field: 'issue', title: '发布人', width: 250, sort: true}
                , {field: 'updateTime', title: '更新时间', width: 250, sort: true}
                , {
                    field: 'status', title: '状态', width: 80, templet: function (d) {
                        var statusStr = '有效';
                        if (d.status != '0') {
                            statusStr = '无效'
                        }
                        return '<span>' + statusStr + '</span>'
                    }
                }
                , {width: 178, align: 'center', fixed: 'right', toolbar: '#ts-app-table-operate-bar'}
            ]]
        });


        /**
         * 列表数据查询方法
         */
        var $ = layui.$, active = {
            reload: function () {
                var id = $('#id').val();
                //执行重载
            }
            , add: function () {
                location.hash = '/app/add'
            }
        };


        //监听工具条
        table.on('tool(ts-app-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                location.hash = "/app/detail/id=" + data.id;
            } else if (obj.event === 'del') {
                layer.confirm('升级信息删除后不可恢复！', function (index) {
                    layer.close(index);
                    var index_ajax = layer.load(2);
                    admin.req({
                        url: 'system/tsApp/delTsAppId.do?id=' + data.id //实际使用请改成服务端真实接口
                        , type: 'get'
                        , done: function (res) {
                            layer.close(index_ajax);
                            if (res.code == 0) {
                                layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                }, function () {
                                    active['reload'] ? active['reload'].call(this) : '';
                                });
                            } else {
                                layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 2
                                    , time: 1000
                                }, function () {
                                });
                                return;
                            }
                        }, success: function (res) {
                            layer.close(index_ajax);
                            console.log(res)
                        }, error: function (res) {
                            layer.close(index_ajax);
                            console.log(res)
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                location.hash = "/app/edit/id=" + data.id;
            }
        });

    });
</script>